define(['jquery', 'bootstrap', 'backend', 'addtabs', 'table', 'echarts', 'echarts-theme', 'template'], function ($, undefined, Backend, Datatable, Table, Echarts, undefined, Template) {

    var Controller = {
        curve: function () {
            // 基于准备好的dom，初始化echarts实例- 注册用户数
            var myChart = Echarts.init(document.getElementById('echart'), 'walden');
            // 指定图表的配置项和数据
            var option = {
                title: {
                    text: '',
                    subtext: ''
                },
                color: [
                    "#18d1b1",
                    "#3fb1e3",
                    "#626c91",
                    "#a0a7e6",
                    "#c4ebad",
                    "#96dee8"
                ],
                tooltip: {
                    trigger: 'axis'
                },
                legend: {
                    data: [__('Register user')]
                },
                toolbox: {
                    show: false,
                    feature: {
                        magicType: {show: true, type: ['stack', 'tiled']},
                        saveAsImage: {show: true}
                    }
                },
                xAxis: {
                    type: 'category',
                    boundaryGap: false,
                    data: Config.column
                },
                yAxis: {},
                grid: [{
                    left: '40',
                    top: '20',
                    right: '40',
                    bottom: 30
                }],
                series: [{
                    name: __('Register user'),
                    type: 'line',
                    smooth: true,
                    areaStyle: {
                        normal: {}
                    },
                    lineStyle: {
                        normal: {
                            width: 1.5
                        }
                    },
                    data: Config.userdata
                }]
            };
            // 使用刚指定的配置项和数据显示图表。
            myChart.setOption(option);
            $(window).resize(function () {
                myChart.resize();
            });
            $(document).on("click", ".btn-refresh", function () {
                setTimeout(function () {
                    myChart.resize();
                }, 0);
            });

            // 帖子数据
            var circleChart = Echarts.init(document.getElementById('circle_echarts'), 'walden');
            // 指定图表的配置项和数据
            var circleOption = {
                title: {
                    text: '',
                    subtext: ''
                },
                color: [
                    "#18d1b1",
                    "#3fb1e3",
                    "#626c91",
                    "#a0a7e6",
                    "#c4ebad",
                    "#96dee8"
                ],
                tooltip: {
                    trigger: 'axis'
                },
                legend: {
                    data: ['帖子数量']
                },
                toolbox: {
                    show: false,
                    feature: {
                        magicType: {show: true, type: ['stack', 'tiled']},
                        saveAsImage: {show: true}
                    }
                },
                xAxis: {
                    type: 'category',
                    boundaryGap: false,
                    data: Config.column
                },
                yAxis: {},
                grid: [{
                    left: '40',
                    top: '20',
                    right: '40',
                    bottom: 30
                }],
                series: [{
                    name: '帖子数量',
                    type: 'line',
                    smooth: true,
                    areaStyle: {
                        normal: {}
                    },
                    lineStyle: {
                        normal: {
                            width: 1.5
                        }
                    },
                    data: Config.circle_data
                }]
            };
            // 使用刚指定的配置项和数据显示图表。
            circleChart.setOption(circleOption);
            $(window).resize(function () {
                circleChart.resize();
            });
            $(document).on("click", ".btn-refresh", function () {
                setTimeout(function () {
                    circleChart.resize();
                }, 0);
            });

            // 发帖、置顶金额
            var priceChart = Echarts.init(document.getElementById('price_echarts'), 'walden');
            // 指定图表的配置项和数据
            var priceOption = {
                title: {
                    text: '',
                    subtext: ''
                },
                color: [
                    "#18d1b1",
                    "#3fb1e3",
                    "#626c91",
                    "#a0a7e6",
                    "#c4ebad",
                    "#96dee8"
                ],
                tooltip: {
                    trigger: 'axis'
                },
                legend: {
                    data: ['发帖、置顶收费']
                },
                toolbox: {
                    show: false,
                    feature: {
                        magicType: {show: true, type: ['stack', 'tiled']},
                        saveAsImage: {show: true}
                    }
                },
                xAxis: {
                    type: 'category',
                    boundaryGap: false,
                    data: Config.column
                },
                yAxis: {},
                grid: [{
                    left: '40',
                    top: '20',
                    right: '40',
                    bottom: 30
                }],
                series: [{
                    name: '发帖、置顶收费',
                    type: 'line',
                    smooth: true,
                    areaStyle: {
                        normal: {}
                    },
                    lineStyle: {
                        normal: {
                            width: 1.5
                        }
                    },
                    data: Config.price_data
                }]
            };
            // 使用刚指定的配置项和数据显示图表。
            priceChart.setOption(priceOption);
            $(window).resize(function () {
                priceChart.resize();
            });
            $(document).on("click", ".btn-refresh", function () {
                setTimeout(function () {
                    priceChart.resize();
                }, 0);
            });

            // 商家认证费用
            var certificationChart = Echarts.init(document.getElementById('certification_echarts'), 'walden');
            // 指定图表的配置项和数据
            var certificationOption = {
                title: {
                    text: '',
                    subtext: ''
                },
                color: [
                    "#18d1b1",
                    "#3fb1e3",
                    "#626c91",
                    "#a0a7e6",
                    "#c4ebad",
                    "#96dee8"
                ],
                tooltip: {
                    trigger: 'axis'
                },
                legend: {
                    data: ['商家认证费用']
                },
                toolbox: {
                    show: false,
                    feature: {
                        magicType: {show: true, type: ['stack', 'tiled']},
                        saveAsImage: {show: true}
                    }
                },
                xAxis: {
                    type: 'category',
                    boundaryGap: false,
                    data: Config.column
                },
                yAxis: {},
                grid: [{
                    left: '40',
                    top: '20',
                    right: '40',
                    bottom: 30
                }],
                series: [{
                    name: '商家认证费用',
                    type: 'line',
                    smooth: true,
                    areaStyle: {
                        normal: {}
                    },
                    lineStyle: {
                        normal: {
                            width: 1.5
                        }
                    },
                    data: Config.certification_data
                }]
            };
            // 使用刚指定的配置项和数据显示图表。
            certificationChart.setOption(certificationOption);
            $(window).resize(function () {
                certificationChart.resize();
            });
            $(document).on("click", ".btn-refresh", function () {
                setTimeout(function () {
                    certificationChart.resize();
                }, 0);
            });

            // 平台扣的保证金
            var groupUserChart = Echarts.init(document.getElementById('group_user_echarts'), 'walden');
            // 指定图表的配置项和数据
            var groupUserOption = {
                title: {
                    text: '',
                    subtext: ''
                },
                color: [
                    "#18d1b1",
                    "#3fb1e3",
                    "#626c91",
                    "#a0a7e6",
                    "#c4ebad",
                    "#96dee8"
                ],
                tooltip: {
                    trigger: 'axis'
                },
                legend: {
                    data: ['平台扣的保证金']
                },
                toolbox: {
                    show: false,
                    feature: {
                        magicType: {show: true, type: ['stack', 'tiled']},
                        saveAsImage: {show: true}
                    }
                },
                xAxis: {
                    type: 'category',
                    boundaryGap: false,
                    data: Config.column
                },
                yAxis: {},
                grid: [{
                    left: '40',
                    top: '20',
                    right: '40',
                    bottom: 30
                }],
                series: [{
                    name: '平台扣的保证金',
                    type: 'line',
                    smooth: true,
                    areaStyle: {
                        normal: {}
                    },
                    lineStyle: {
                        normal: {
                            width: 1.5
                        }
                    },
                    data: Config.group_user_data
                }]
            };
            // 使用刚指定的配置项和数据显示图表。
            groupUserChart.setOption(groupUserOption);
            $(window).resize(function () {
                groupUserChart.resize();
            });
            $(document).on("click", ".btn-refresh", function () {
                setTimeout(function () {
                    groupUserChart.resize();
                }, 0);
            });

            require(['bootstrap-daterangepicker'], function () {
                $('#fetchDataBtn').daterangepicker({
                    "startDate": Config.start_date,
                    "endDate": Config.end_date,
                    "locale": {
                        format: 'YYYY-MM-DD',
                        separator: ' ~ ',
                        applyLabel: "确认",
                        cancelLabel: "取消"
                    }
                }, function(start, end, label) {
                    timeRangeChange = [start.format('YYYY-MM-DD HH:mm:ss'), end.format('YYYY-MM-DD HH:mm:ss')];
                    // 发起AJAX请求
                    $.ajax({
                        url: '/fQlTgiAVKu.php/dashboard/curveList',
                        type: 'POST',
                        data: {
                            start_time: timeRangeChange[0],
                            end_time: timeRangeChange[1]
                        },
                        success: function(response) {
                            // 处理响应
                            console.log(response);
                            var option = {
                                title: {
                                    text: '',
                                    subtext: ''
                                },
                                color: [
                                    "#18d1b1",
                                    "#3fb1e3",
                                    "#626c91",
                                    "#a0a7e6",
                                    "#c4ebad",
                                    "#96dee8"
                                ],
                                tooltip: {
                                    trigger: 'axis'
                                },
                                legend: {
                                    data: [__('Register user')]
                                },
                                toolbox: {
                                    show: false,
                                    feature: {
                                        magicType: {show: true, type: ['stack', 'tiled']},
                                        saveAsImage: {show: true}
                                    }
                                },
                                xAxis: {
                                    type: 'category',
                                    boundaryGap: false,
                                    data: response.column
                                },
                                yAxis: {},
                                grid: [{
                                    left: '40',
                                    top: '20',
                                    right: '40',
                                    bottom: 30
                                }],
                                series: [{
                                    name: __('Register user'),
                                    type: 'line',
                                    smooth: true,
                                    areaStyle: {
                                        normal: {}
                                    },
                                    lineStyle: {
                                        normal: {
                                            width: 1.5
                                        }
                                    },
                                    data: response.userdata
                                }]
                            };
                            // 使用刚指定的配置项和数据显示图表。
                            myChart.setOption(option);

                            // 帖子数据
                            var circleOption = {
                                title: {
                                    text: '',
                                    subtext: ''
                                },
                                color: [
                                    "#18d1b1",
                                    "#3fb1e3",
                                    "#626c91",
                                    "#a0a7e6",
                                    "#c4ebad",
                                    "#96dee8"
                                ],
                                tooltip: {
                                    trigger: 'axis'
                                },
                                legend: {
                                    data: ['帖子数量']
                                },
                                toolbox: {
                                    show: false,
                                    feature: {
                                        magicType: {show: true, type: ['stack', 'tiled']},
                                        saveAsImage: {show: true}
                                    }
                                },
                                xAxis: {
                                    type: 'category',
                                    boundaryGap: false,
                                    data: response.column
                                },
                                yAxis: {},
                                grid: [{
                                    left: '40',
                                    top: '20',
                                    right: '40',
                                    bottom: 30
                                }],
                                series: [{
                                    name: '帖子数量',
                                    type: 'line',
                                    smooth: true,
                                    areaStyle: {
                                        normal: {}
                                    },
                                    lineStyle: {
                                        normal: {
                                            width: 1.5
                                        }
                                    },
                                    data: response.circle_data
                                }]
                            };
                            // 使用刚指定的配置项和数据显示图表。
                            circleChart.setOption(circleOption);

                            // 发帖、置顶金额
                            var priceOption = {
                                title: {
                                    text: '',
                                    subtext: ''
                                },
                                color: [
                                    "#18d1b1",
                                    "#3fb1e3",
                                    "#626c91",
                                    "#a0a7e6",
                                    "#c4ebad",
                                    "#96dee8"
                                ],
                                tooltip: {
                                    trigger: 'axis'
                                },
                                legend: {
                                    data: ['发帖、置顶收费']
                                },
                                toolbox: {
                                    show: false,
                                    feature: {
                                        magicType: {show: true, type: ['stack', 'tiled']},
                                        saveAsImage: {show: true}
                                    }
                                },
                                xAxis: {
                                    type: 'category',
                                    boundaryGap: false,
                                    data: response.column
                                },
                                yAxis: {},
                                grid: [{
                                    left: '40',
                                    top: '20',
                                    right: '40',
                                    bottom: 30
                                }],
                                series: [{
                                    name: '发帖、置顶收费',
                                    type: 'line',
                                    smooth: true,
                                    areaStyle: {
                                        normal: {}
                                    },
                                    lineStyle: {
                                        normal: {
                                            width: 1.5
                                        }
                                    },
                                    data: response.price_data
                                }]
                            };
                            // 使用刚指定的配置项和数据显示图表。
                            priceChart.setOption(priceOption);

                            // 商家认证费用
                            var certificationOption = {
                                title: {
                                    text: '',
                                    subtext: ''
                                },
                                color: [
                                    "#18d1b1",
                                    "#3fb1e3",
                                    "#626c91",
                                    "#a0a7e6",
                                    "#c4ebad",
                                    "#96dee8"
                                ],
                                tooltip: {
                                    trigger: 'axis'
                                },
                                legend: {
                                    data: ['商家认证费用']
                                },
                                toolbox: {
                                    show: false,
                                    feature: {
                                        magicType: {show: true, type: ['stack', 'tiled']},
                                        saveAsImage: {show: true}
                                    }
                                },
                                xAxis: {
                                    type: 'category',
                                    boundaryGap: false,
                                    data: response.column
                                },
                                yAxis: {},
                                grid: [{
                                    left: '40',
                                    top: '20',
                                    right: '40',
                                    bottom: 30
                                }],
                                series: [{
                                    name: '商家认证费用',
                                    type: 'line',
                                    smooth: true,
                                    areaStyle: {
                                        normal: {}
                                    },
                                    lineStyle: {
                                        normal: {
                                            width: 1.5
                                        }
                                    },
                                    data: response.certification_data
                                }]
                            };
                            // 使用刚指定的配置项和数据显示图表。
                            certificationChart.setOption(certificationOption);

                            // 平台扣的保证金
                            var groupUserOption = {
                                title: {
                                    text: '',
                                    subtext: ''
                                },
                                color: [
                                    "#18d1b1",
                                    "#3fb1e3",
                                    "#626c91",
                                    "#a0a7e6",
                                    "#c4ebad",
                                    "#96dee8"
                                ],
                                tooltip: {
                                    trigger: 'axis'
                                },
                                legend: {
                                    data: ['平台扣的保证金']
                                },
                                toolbox: {
                                    show: false,
                                    feature: {
                                        magicType: {show: true, type: ['stack', 'tiled']},
                                        saveAsImage: {show: true}
                                    }
                                },
                                xAxis: {
                                    type: 'category',
                                    boundaryGap: false,
                                    data: response.column
                                },
                                yAxis: {},
                                grid: [{
                                    left: '40',
                                    top: '20',
                                    right: '40',
                                    bottom: 30
                                }],
                                series: [{
                                    name: '平台扣的保证金',
                                    type: 'line',
                                    smooth: true,
                                    areaStyle: {
                                        normal: {}
                                    },
                                    lineStyle: {
                                        normal: {
                                            width: 1.5
                                        }
                                    },
                                    data: response.group_user_data
                                }]
                            };
                            // 使用刚指定的配置项和数据显示图表。
                            groupUserChart.setOption(groupUserOption);
                        },
                    });
                });
            });
        }
    };

    return Controller;
});
